package com.itboye.eweilisten.me.timu.adapter;

import android.content.Context;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.widget.ImageView;


import com.itboye.eweilisten.R;
import com.itboye.eweilisten.adapter.MutiplyCommonAdapter;
import com.itboye.eweilisten.adapter.ViewHolder;
import com.itboye.eweilisten.model.TIbean;
import com.itboye.eweilisten.model.TIbeanTwo;

import com.itboye.eweilisten.util.sputil.Const;
import com.itboye.eweilisten.util.widget.XImageLoader;


import java.util.ArrayList;
import java.util.List;

/**
 * 听录音 选择正确图片
 */
public class TiAtwoAdapter extends MutiplyCommonAdapter<TIbean.Options> {
    ArrayList<TIbean.Options> datas;
    ArrayList<String> answer_truev;
    int iii;
    List<TIbeanTwo> list;

    public TiAtwoAdapter(Context context, ArrayList<TIbean.Options> datas, ArrayList<String> answer_truev, int iii, List<TIbeanTwo> list, int... layoutId) {
        super(context, datas, layoutId);
        this.datas = datas;
        this.answer_truev = answer_truev;
        this.iii = iii;
        this.list = list;
    }

    @Override
    public int getItemViewType(int position) {
        return 0;
    }

    @Override
    public void getItemPosition(int position) {

    }

    @Override
    public void convert(final ViewHolder holder, final TIbean.Options t, int type, final int position) {
        holder.setText(R.id.include_text, t.getOptions());

        //使用此方法判断，防止点击图片重新加载闪烁问题
        if (t.getNeirong().equals(holder.getView(R.id.include_text).getTag())) {

        } else {
            // 如果不相同，就加载。现在在这里来改变闪烁的情况

            XImageLoader.load(Const.IMAGE_HEAD + t.getNeirong(), (ImageView) holder.getView(R.id.include_image));
            holder.setTag(R.id.include_text, t.getNeirong());
        }

        if (t.isDa()) {
            holder.setTextColorRes(R.id.include_text, R.color.white);
            holder.setBackgroundRes(R.id.include_text, R.drawable.shap_circle01);
        } else {
            holder.setTextColorRes(R.id.include_text, R.color.blue);
            holder.setBackgroundRes(R.id.include_text, R.drawable.shap_circle);
        }
        holder.setTag(R.id.include_text, R.id.tag, t.getOptions());
        holder.setOnClickListener(R.id.store_luntai, position, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i < datas.size(); i++) {
                    datas.get(i).setDa(false);
                }
                t.setDa(true);

                String tag = holder.getView(R.id.include_text).getTag(R.id.tag).toString();
                System.out.println("JHHHKHHHIKHUHUY:" + tag);

                int poistions = answer_truev.indexOf(holder.getView(R.id.include_text).getTag(R.id.tag).toString());
                if (poistions == -1) {
                    list.get(iii).setXuan(1);//1代表选择错误

                } else {
                    list.get(iii).setXuan(0);//0代表选择正确
                }
                notifyDataSetChanged();
            }
        });
    }

}
